package com.jerry.cui.dingtalk.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dingtalk.api.request.OapiV2UserUpdateRequest;
import com.dingtalk.api.response.OapiUserGetResponse;
import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
import com.dingtalk.api.response.OapiV2UserUpdateResponse;
import com.jerry.cui.dingtalk.service.DingTalkUserService;
import com.taobao.api.ApiException;

@RestController
@RequestMapping("user")
public class DingTalkUserController {

	@Autowired
	DingTalkUserService dingTalkUserService;

	@GetMapping("get")
	public OapiUserGetResponse getUser(@RequestParam String userId,
			@RequestParam(required = false) Boolean fetchChild) {
		try {
			return dingTalkUserService.getUser(userId);
		} catch (ApiException e) {
			e.printStackTrace();
		}
		return null;
	}
	@PostMapping("getbymobile")
	public OapiV2UserGetbymobileResponse getbymobile(@RequestParam String mobile ) {
		try {
			return dingTalkUserService.getbymobile(mobile);
		} catch (ApiException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@PostMapping("updateUser")
	public OapiV2UserUpdateResponse updateUser(@RequestBody OapiV2UserUpdateRequest request ) {
		try {
			return dingTalkUserService.updateUser(request);
		} catch (ApiException e) {
			e.printStackTrace();
		}
		return null;
	}

}
